
#define LARGE_MESSAGE_SIZE 0x40000

typedef enum _SYSDBG_COMMAND {
    SysDbgQueryModuleInformation,
    SysDbgQueryTraceInformation,
    SysDbgSetTracepoint,
    SysDbgSetSpecialCall,
    SysDbgClearSpecialCalls,
    SysDbgQuerySpecialCalls,
    SysDbgBreakPoint,
    SysDbgQueryVersion,
    SysDbgReadVirtual,
    SysDbgWriteVirtual,
    SysDbgReadPhysical,
    SysDbgWritePhysical,
    SysDbgReadControlSpace,
    SysDbgWriteControlSpace,
    SysDbgReadIoSpace,
    SysDbgWriteIoSpace,
    SysDbgReadMsr,
    SysDbgWriteMsr,
    SysDbgReadBusData,
    SysDbgWriteBusData,
    SysDbgCheckLowMemory,
    SysDbgEnableKernelDebugger,
    SysDbgDisableKernelDebugger,
    SysDbgGetAutoKdEnable,
    SysDbgSetAutoKdEnable,
    SysDbgGetPrintBufferSize,
    SysDbgSetPrintBufferSize,
    SysDbgGetKdUmExceptionEnable,
    SysDbgSetKdUmExceptionEnable,
    SysDbgGetTriageDump,
    SysDbgGetKdBlockEnable,
    SysDbgSetKdBlockEnable,
}SYSDBG_COMMAND, *PSYSDBG_COMMAND;

typedef struct _SYSDBG_VIRTUAL {
    PVOID Address;
    PVOID Buffer;
    ULONG Request;
}SYSDBG_VIRTUAL, *PSYSDBG_VIRTUAL;

#pragma pack(1)
typedef struct _CALL_GATE{
	WORD addrlo;
	WORD seg;
	BYTE arg:5;
	BYTE u:3;
	BYTE typ:5;
	BYTE dpl:2;
	BYTE pres:1;
	WORD addrhi;
}CALL_GATE;

typedef struct _LDR_MODULE 
{
	LIST_ENTRY InLoadOrderModuleList;  //<-- InLoad points here
	LIST_ENTRY InMemoryOrderModuleList; //<-- PInMem points here
	LIST_ENTRY InInitializationOrderModuleList;  //<-- InInitia points here
	PVOID BaseAddress; 
	PVOID EntryPoint; 
	ULONG SizeOfImage; 
	UNICODE_STRING FullDllName; 
	UNICODE_STRING BaseDllName; 
	ULONG Flags; 
	SHORT LoadCount; 
	SHORT TlsIndex; 
	LIST_ENTRY HashTableEntry; 
	ULONG TimeDateStamp;
}LDR_MODULE, *PLDR_MODULE;

typedef struct _SECTION_BASIC_INFORMATION
{ // Information Class 0
	PVOID BaseAddress;
	ULONG Attributes;
	LARGE_INTEGER Size;
}SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION;

struct CLLHook
{
	SLIST_ENTRY HookEntry;
	bool        Installed;//0 is not installed 1 if installed
	BYTE        Opcode;//e9 jmp e8 call
	int         Index;
	LPVOID      pHeap;
	DWORD       TProcessId;//Targets ProcessId
	DWORD       hkTAddress;//Target Function to Hook
	DWORD       hkAddress;//Hook address
	PVOID       hkAllocAddr;
	DWORD       hkSz;//our hook size generally 5 bytes byte+dword
};

typedef struct _SIN32_CLIENT_ENTRY
{
	LIST_ENTRY ClientList;
	HANDLE ProcessId;
	HANDLE ServerThread;
	HANDLE ThreadId;
	HANDLE ClientPort;
	PORT_VIEW ServerView;
	REMOTE_PORT_VIEW ClientView;
}SIN_CLIENT_ENTRY,PSIN_CLIENT_ENTRY;

typedef struct _SIN_CLIENT_CONNECT
{
     ULONG ServerId;
     PVOID ClientInfo;
     ULONG ClientInfoSize;
}SIN_CLIENT_CONNECT,*PSIN_CLIENT_CONNECT;

typedef enum _SIN_API_TYPE
{
	SIN_INJECT_CLIENT = 1,
	SIN_INJECT_DLL,
	SIN_INJECT_MEMORY,
	SIN_MAP_CODE,
	SIN_MAP_RUN_CODE,
	SIN_REMOTE_HOOK,
	SIN_REMOTE_VEH_TAKEOVER,
	SIN_SUSPEND_CLIENT,
	SIN_WAIT_SERVER
}SIN_API_TYPE;

typedef struct _SIN_REQUEST_INJECT_CLIENT
{
	char			ProcessName[50];
}SIN_REQUEST_INJECT_CLIENT,*PSIN_REQUEST_INJECT_CLIENT;

typedef struct _SIN_REQUEST_INJECT_DLL
{
	char				ProcessName[50];
	char				DllPath[50];
}SIN_REQUEST_INJECT_DLL,*PSIN_REQUEST_INJECT_DLL;

typedef struct _SIN_REQUEST_REMOTE_HOOK
{
	CLLHook				HookMsg;	
	char				ProcessName[50];
}SIN_REQUEST_REMOTE_HOOK,*PSIN_REQUEST_REMOTE_HOOK;

typedef struct _SIN_REQUEST_VEH_TAKEOVER
{
	ULONG				HandleExceptionType;
	ULONG				TargetFunc;
	ULONG               HookFunc;	
	char				ProcessName[50];
}SIN_REQUEST_VEH_TAKEOVER,*PSIN_REQUEST_VEH_TAKEOVER;

typedef struct _SIN_API_MESSAGE
{
   PORT_MESSAGE Header;
   ULONG Data;
   ULONG Status;
   ULONG StartAddress;
   ULONG ApiType;
   SIN_CLIENT_ENTRY ClientInfo;
   union
   {
	   SIN_REQUEST_VEH_TAKEOVER ReqVehHook;
	   SIN_REQUEST_REMOTE_HOOK	 ReqRemoteHook;
	   SIN_REQUEST_INJECT_DLL   ReqDllInject;
	   SIN_REQUEST_INJECT_CLIENT ReqInjectClient;
   }ApiInfo;
}SIN_API_MESSAGE, *PSIN_API_MESSAGE;

__forceinline void InitializeSinApiMessage(SIN_API_MESSAGE *ph,USHORT len,LPC_TYPE type,SIN_API_TYPE apitype)
{
    ph->Header.u1.s1.TotalLength    = len;
    ph->Header.u1.s1.DataLength     = len - sizeof(PORT_MESSAGE); 
    ph->Header.u2.s2.Type           = (USHORT)(type);
    ph->Header.u2.s2.DataInfoOffset = 0;                                  
	ph->ApiType			   = (ULONG)(apitype);
}																



